using System;
using Science.Mathematics;
using L=Science.Physics.GeneralPhysics;
using M = Science.Mathematics.Calculus;


namespace Serway.Chapter17
{
	/// <summary>
	/// Example05: The Broken Clock Radio
	/// Your clock radio awakens you with a steady and
	/// irritating sound of frequency 600 Hz. One morning,
	/// it malfunctions and cannot be turned off. In frustration,
	/// you drop the clock radio out of your fourth-story
	/// dorm windows, 15.0 m from the ground. Assume
	/// the speed of sound is 343 m/s.
	/// (A) As you listen to the falling clock radio, what frequency 
	/// do you hear just before you hear the radio striking 
	/// the ground?
	/// f' = 571 Hz
	/// (B) At what rate does the frequency that you hear change
	/// with time just before you hear the radio striking
	/// the ground?
	/// df'/dt = -15.5 Hz
	/// </summary>
	public class Example05
	{
		public Example05()
		{
		}
		private string result;
		public string Result
		{
			get{return result;}
		}
		public void Compute()
		{
			L.Frequency f = new L.Frequency();
			f.Hz = 600.0;
			double s = 15.0;
			double g = L.Constant.AccelerationOfGravity;
			L.Speed vs = new L.Speed();
			vs.mPERs = -g*Math.Sqrt(2.0*s/g);
			L.Frequency fo = new L.Frequency();
			fo.VariableQ = true;
			L.Speed vo = new L.Speed();
			L.Sound sound = new L.Sound();
			sound.DopplerEffect(f,vs,fo,vo);
			//(A)
			result+=Convert.ToString(fo.Hz)+"\r\n";
            //(B)
	    	Function.DoubleToDouble func = new Function.DoubleToDouble(vel);
			M.Derivative obj = new M.Derivative(func);
			obj.At = Math.Sqrt(2.0*s/g);
			obj.Compute();
			result+=Convert.ToString(obj.Result); 
		}
		private double vel(double t)
		{
			return 600.0*(343.0+0.0)/(343.0+9.8*t);
		}
	}
}
